package arithmetic;

//打家劫舍
//dp[i]=max(dp[i−2]+nums[i],dp[i−1])


public class Arithmetic15 {
    public static int fun(int[] arr){
        if (arr.length==0||arr == null){
            return 0;
        }
        if (arr.length ==1){
            return arr[0];
        }
        int[] dp = new int[arr.length];
        dp[0] = arr[0];
        dp[1] =Math.max(arr[0],arr[1]);
        for (int i = 2; i <arr.length ; i++) {
            dp[i] = Math.max(dp[i-2]+arr[i],dp[i-1]);
        }
        return  dp[dp.length-1];
    }

    public static void main(String[] args) {
        int[] arr = {2,43,4,3,2,6};
        System.out.println(Arithmetic15.fun(arr));
    }

}

